package com.jse.reflection;

import org.junit.Test;

import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017/7/24.
 */
public class SimpleTest {

    @Test
    public void testMethodInvoke() {
        AHuman human = new AHuman();
        human.setName("duke");

        Object object = human;

        Class<?> clazz = object.getClass();
        try {
            Method method = clazz.getDeclaredMethod("setName", String.class);
            //object就是执行方法的来源
            method.invoke(object, "hello");
            System.out.println(human.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
